<#assign tit><#if _oper='add'>新增<#else>修改</#if>门店通知</#assign>
<@page.html title=tit>
<script type="text/javascript" src="${_appPath!}/js/upload.js"></script>
<script type="text/javascript">
  function initssel() {
    getJson("getShopList", function(data){
      if(data.ret && data.data) {
        _shopls = data.data.shops;
        _areals = data.data.areas;
        _areatp = data.data.areatp;
        slpinit();
      }
    });
  }
  function slpinit() {
    if(!_shopls || _shopls.length==0) return;
    var i, j, shop, sp;
    sp = getEl("sp_recvName");
    if(sp) sp.innerHTML = "全部门店";
    var arr = [];
    arr.push('<div id="dv_selhd" class="selhd"><input type="button" class="sel" value="选择门店" onclick="slpchg(0);" />');
    for(i=0; _areatp && i<_areatp.length; i++)
      arr.push('<input type="button" value="'+_areatp[i][1]+'区域" onclick="slpchg('+(i+1)+');" />');
    arr.push('</div>');
    arr.push('<div id="dv_sels_0"><div class="selqy">输入关键字：<input type="text" onkeyup="slpfdsh(this.value);"></div><div id="dv_selsh" class="selsh">');
    for(i=0; i<_shopls.length; i++)
      arr.push('<label><input type="checkbox" id="cb_slp_shop_'+_shopls[i][0]+'" value="'+_shopls[i][0]+'" checked onclick="slpselsh(this);" kw="'+_shopls[i][0]+'/'+_shopls[i][1]+'/'+_shopls[i][2]+'"><span>'+_shopls[i][0]+'-'+_shopls[i][1]+'</span></label>');
    arr.push('</div></div>');
    for(j=0; _areatp && j<_areatp.length; j++) {
      arr.push('<div id="dv_sels_'+(j+1)+'" class="selar" style="display:none;">');
      for(i=0; i<_areals.length; i++)
        if(_areals[i][2]==_areatp[j][0])
          arr.push('<label><input type="checkbox" value="'+_areals[i][0]+'" checked onclick="slpselar(this);">'+_areals[i][1]+'('+_areals[i][3].length+')</label>');
      arr.push('</div>');
    }
    arr.push('<div class="selft"><span style="margin-right:10px;">选择了<span id="sp_selst">全部'+_shopls.length+'</span>家门店</span>'
        + '<input type="button" value="全选" onclick="slpselall();"><input type="button" value="全清" onclick="slpselnone();">'
        + '<input type="button" class="button" value="确定" onclick="slpselok();"></div>');
    var div = getEl('dv_shopsel');
    if(div) div.innerHTML = arr.join('');

    _shopselnum = _shopls.length;
  }
  function slpselok() {
    if(_shopselnum<=0) {
      window.alert("请选择门店!");
      return;
    }
    var ipt = getEl("ipt_recvCode");
    if(_shopselnum==_shopls.length) {
      if(ipt) ipt.value = "0-all";
      ipt = getEl("sp_recvName");
      if(ipt) ipt.innerHTML = "全部门店";
    } else {
      var div = getEl("dv_selsh");
      if(!div) return;
      var i,nam=null,shs = [];
      for(i=0; i<div.childNodes.length; i++) {
        if(div.childNodes[i].childNodes[0].checked) {
          shs.push("3-"+div.childNodes[i].childNodes[0].value);
          if(!nam) nam = div.childNodes[i].childNodes[1].innerHTML;
        }
      }
      if(ipt) ipt.value = shs.join(",");
      ipt = getEl("sp_recvName");
      if(ipt) {
        if(shs.length==1) {
          ipt.innerHTML = nam;
        } else {
          ipt.innerHTML = "已选"+_shopselnum+"家门店";
        }
      }
    }
    slpclose();
  }

  function uploadSucc(f) {
    var td = getEl("td_img");
    if(td) {
      var sp = document.createElement("SPAN");
      td.appendChild(sp);
      sp.innerHTML = '<img src="${_picPath!}'+ f.furl+'" style="max-width:220px;"/>';
    }
    var ipt = getEl("ipt_pics");
    ipt.value = ipt.value + (ipt.value!=""?",":"") + f.furl;
  }
</script>
<div style="width:650px;">
  <div class="kbox">
    <form id="fm_input" method="post" action="<#if _oper='add'>_add<#else>_edit</#if>" onsubmit="return post(this);">
      <input type="hidden" name="msgId" value="${message.msgId!}">
      <input type="hidden" name="recvCode" id="ipt_recvCode" value="${message.recvCode!}" req="接收部门">
      <input type="hidden" name="picUrls" id="ipt_pics" value="">
      <table class="input">
        <tr>
          <th width="100">接收门店</th>
          <td><div id="dv_shopsel" class="shopsel" style="display:none;" onclick="eventCancel(event);"></div><span id="sp_recvName"></span>
            <input type="button" class="opwin" value="选择..." onclick="slpshow(event);"/></td>
        </tr>
        <tr>
          <th>标题</th>
          <td><input type="text" name="title" value="${message.title!}" req="标题" size="40" maxlength="50" style="width:400px;"></td>
        </tr>
        <tr>
          <th>内容</th>
          <td><textarea name="content" cols="40" rows="6" req="内容" style="width:400px; height:200px;">${message.content!}</textarea></td>
        </tr>
      </table>
    </form>
    <table class="input">
      <tr>
        <th width="100">上传图片</th>
        <td><form id="fm_upload" action="_upload" method="post" enctype="multipart/form-data" target="ifm_upload">
          <input type="file" name="file" id="ip_file" size="22" /> <input type="button" class="opwin" value="上传" onclick="chkupload();"></form>
          <iframe name="ifm_upload" onload="uploadOk(this);" style="width:0px; height:0px; display:none;"></iframe>
          <div id="div_wait" style="position:absolute; display:none; border:1px solid #999; top:-5px; left:50px; background-color:#fffff0; padding:12px 50px;"><span class="loading">正在上传，请稍等。。。</span></div></td>
      </tr>
      <tr>
        <th></th>
        <td id="td_img"></td>
      </tr>
    </table>
  </div>
  <div class="button"><input type="button" value="提 交" onclick="post(getEl('fm_input'));"></div>
</div>
<script>initssel();</script>
</@page.html>